/**
 * 对象扩展
 * Rest Spread
 * 
 * es9 Promise 扩展：Promise.prototype.finally()
 * 
 * 字符串扩展
 * 
 * 对象扩展 es10
 * Object.fromEntries()
 * 
 * 字符串扩展
 * String.prototype.trimStart()
 * 
 * 数组扩展
 * Array.prototype.flat()
 * 
 * 函数扩展
 * Function.prototype.toString()
 * 
 * Json 扩展 
 * JSON superset
 * JSON.stringify()
 * 
 * Symbol 扩展
 *
Catch binding

Symbol.prototype.description()
 */

 new Promise((resolve, reject) => {
   setTimeout(() => {
     reject('fail')
   },1000)
 }).then((res) => {
   console.log(res)
 }).catch(err => {
   console.log(err)
 }).finally(() => {
   console.log('finally')
 })

 const foo = arg => {
   console.log(arg)
 }

 // 标签模板字符串
 foo`\u{61} \u{62}`


 /**
  * 对象转数组
  */
 const obj = {
   name:'aqie',
   age:12
 }
 const entries = Object.entries(obj)
 console.log(entries)

 /**
  * 数组转对象
  */
 const obj2 = Object.fromEntries(entries)
 console.log(obj2)

 /**
  * 应用 map 转对象
  */
 const map = new Map()
 map.set('name','aqie')
 map.set('sex', 1)
 console.log(map)
 const mapObj = Object.fromEntries(map)
 console.log(mapObj)

 /**
  * 应用2 ： 输出所有分数大于80分
  */
 const course = {
   math: 80,
   english:85,
   chinese:90
 }
 const courseArr = Object.entries(course)
 const courseRes = Object.fromEntries(courseArr.filter(([k, v]) => v > 80))
 console.log('courseRes',courseRes)

 const str = '    aqie     '
 console.log(str.replace(/^\s+/g, ''))
 console.log(str.replace(/\s+$/g, ''))
 console.log(str.trimStart())
 console.log(str.trimEnd())

 let arrDouble = [1,2,3,[4,5]]
 console.log(arrDouble.flat())

function sum(a , b) {
  return a + b
}

console.log(sum.toString())

try {
  throw 0;
} catch {
  doSomethingWhichDoesNotCareAboutTheValueThrown();
} finally {
  doSomeCleanup();
}

function doSomeCleanup(params) {
  
}

function doSomethingWhichDoesNotCareAboutTheValueThrown(params) {
  
}

/* eval('var str="aqie"; function foo2() {return str;}')
console.log(foo2()) */
// 段分隔符\u2029  行分隔符\u2028

// JSON.stringify() 解析范围 0xD800~0xDfff
console.log(JSON.stringify('\uD83D\uDE0E'))

// Symbol 扩展
const s = Symbol('1')
console.log(s.description) // 只读属性